package com.zzc.study.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClientController
{

    @Autowired
    private ChatClient chatClient;

    // http://localhost:8082/chat?msg=%E6%B7%B1%E5%9C%B3
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "msg",defaultValue = "今天天气如何？") String msg) {
        String response = chatClient.prompt()
                .user(msg)
                .call()
                .content();
        System.out.println("响应结果: " + response);
        return response;
    }

    // http://localhost:8082/express?msg=%E5%B7%B2%E9%80%80%E8%B4%A7
    @GetMapping("/express")
    public String express(@RequestParam(value = "msg",defaultValue = "在路上") String msg) {
        String response = chatClient.prompt()
                .user(msg)
                .call()
                .content();
        System.out.println("响应结果: " + response);
        return response;
    }
}